(function (app) {

    //app.controller('MyCtrl', MyCtrl);
    app.controller({
        MyCtrl: ['$scope', '$timeout', '$rootScope', 'MyServer', function ($scope, $timeout, $rootScope, MyServer) {
            $rootScope.name = 'rootScope';
            $scope.name = 'scope';
            this.name = 'controller';
            console.log($rootScope, $scope);
            MyServer.getUsers()
                .then(function (res) {
                    $scope.users = res.data;
                });
        }],
        Ctrl  : ['$scope', function (scope) {
            scope.name = 'child'
        }]
    });

    app.service('MyServer', ['$http',function ($http) {
        this.sayHi = function () {
            alert('Hi!');
        };
        this.hello = function () {
            alert('Hello!');
        };
        this.getUsers = function () {
            var promise = $http({
                method: 'get',
                url: './data.json'
            });
            promise.finally(function () {
                console.log('完成请求');
            });
            return promise;
        };
    }]);
})(angular.module('app', []));